package com.hubn.text;

import com.dao.UserDao;
import com.hbnu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationContext {
    public static void main(String[] args) {
//     ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        UserService userService = (UserService) applicationContext.getBean("userService");
//        System.out.println(userService);
        //factory1
//        Object userDao1 = applicationContext.getBean("userDao1");
//        System.out.println(userDao1);
//        //factory2
//        Object userDao2 = applicationContext.getBean("userDao2");
//        System.out.println(userDao2);
//        UserService userService = (UserService) applicationContext.getBean("userService");
//        userService.show();
        //注入测试@value
//        UserDao bean = applicationContext.getBean(UserDao.class);
//        bean.show();
        //注入测试@Autowired
//        UserService bean = (UserService)applicationContext.getBean("UserService");
//        bean.show();
//        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");

        ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext2.xml");
//        UserService userService = app.getBean(UserService.class);
//        userService.show1();
//        userService.show2();
        UserService bean = app.getBean(UserService.class);
        bean.show1();
        bean.show2();
    }
}
